<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Hugo 0.88.1">
    <!-- 解决ajax被spring security的CSRF拦截POST和PUT请求问题 -->
    <meta name="_csrf" th:content="${_csrf.token}">
    <meta name="_csrf_header" th:content="${_csrf.headerName}">
    <title>签到</title>

    <!-- Bootstrap core CSS -->
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <style>
        @media (min-width: 768px) {
            #un {
                color: var(--light);
                font-size: 1.1rem;
            }

            .sign {
                background: #f3f4f6;
            }

            #main div div div {
                background: white;
            }
        }

    </style>
    <!-- Custom styles for this template -->
    <link th:href="@{/css/dashboard.css}" rel="stylesheet">
    <link th:href="@{/css/toastr.min.css}" rel="stylesheet">

</head>
<body onload="app()">

<div th:replace="~{common :: top-nav}"></div>

<div class="container-fluid">
    <div class="row">
        <!--左侧导航-->
        <div class="col-2">
            <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                <a class="nav-link" id="v-pills-home-tab" role="tab" aria-selected="true" th:href="@{/login/main}" sec:authorize="hasAnyRole('STUDENT','GUARD','MG','TESTER')">个人信息</a>
                <a class="nav-link" id="v-pills-profile-tab" role="tab" aria-selected="false" th:href="@{/access/info(id=${session.user.id})}" sec:authorize="hasRole('STUDENT')">出入记录</a>
                <a class="nav-link" id="v-pills-result-tab" role="tab" aria-selected="false" th:href="@{/detected/findResultByNo(id=${session.user.id})}" sec:authorize="hasRole('STUDENT')">核酸检测结果信息</a>
                <a class="nav-link" id="v-pills-sign-ed" role="tab" aria-selected="false" th:href="@{/stu/sign-formation}" sec:authorize="hasRole('STUDENT')">签到信息</a>
            </div>
        </div>
        <!-- 签到 -->
        <div class="col-10 sign divider" id="main">
            <div class="tab-pane fade show active" role="tabpanel" sec:authorize="hasAnyRole('STUDENT')">
                <div class="row justify-content-center py-2">
                    <div class="col-md-10 col-sm-10" id="MyMessage">
                        <h4 class="mb-3">
                            学生健康上报
                        </h4>
                        <hr class="mb-1"/>
                        <small>为了避免新型冠状病毒在学校内传播，请各位如实填写！</small>
                        <form class="needs-validation" th:action="@{/security/sign}" method="post" novalidate>
                            <!-- 体温 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span class="text-primary">*01. </span>今天你的体温时多少？</label>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="tw" id="zc" value="37.2度及以下"
                                           required>
                                    <label class="custom-control-label" for="zc">37.2度及以下</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="tw" id="fs" value="37.3度-37.9度"
                                           required>
                                    <label class="custom-control-label" for="fs">37.3度-37.9度</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="tw" id="fgs" value="38度以上"
                                           required>
                                    <label class="custom-control-label" for="fgs">38度以上</label>
                                </div>
                            </div>
                            <!-- 身体健康状态 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span class="text-primary">*02. </span>今天你的身体状况是？</label>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="bd" id="bd-jk" value="健康"
                                           required>
                                    <label class="custom-control-label" for="bd-jk">健康</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="bd" id="bd-fs" value="发烧"
                                           required>
                                    <label class="custom-control-label" for="bd-fs">发烧</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="bd" id="bd-fl" value="乏力"
                                           required>
                                    <label class="custom-control-label" for="bd-fl">乏力</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="bd" id="bd-gk" value="干咳"
                                           required>
                                    <label class="custom-control-label" for="bd-gk">干咳</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="bd" id="bd-other" value="其他"
                                           required>
                                    <label class="custom-control-label" for="bd-other">其他</label>
                                </div>
                            </div>
                            <!-- 共同居主人接触史1 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span
                                        class="text-primary">*03. </span>近14天你的共同居主人是否有疫情中、高风险区域人员接触史？</label>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="jc" id="u-yes" value="1"
                                           required>
                                    <label class="custom-control-label" for="u-yes">是</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="jc" id="u-no" value="0"
                                           required>
                                    <label class="custom-control-label" for="u-no">否</label>
                                </div>
                            </div>
                            <!-- 共同居主人接触史2 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span
                                        class="text-primary">*04. </span>近14天你的共同居主人是否和确诊、疑似病人接触过？</label>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="jc2" id="u4-yes" value="1"
                                           required>
                                    <label class="custom-control-label" for="u4-yes">是</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="jc2" id="u4-no" value="0"
                                           required>
                                    <label class="custom-control-label" for="u4-no">否</label>
                                </div>
                            </div>
                            <!-- 是否属实 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span class="text-primary">*05. </span>本人是否承若以上所填报的全部内容均属实、准确，不存在任何隐瞒与不实的情况、更无遗漏之处？</label>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="ss" id="u5-yes" value="1" required>
                                    <label class="custom-control-label" for="u5-yes">是</label>
                                </div>
                                <div class="custom-control custom-radio">
                                    <input class="custom-control-input" type="radio" name="ss" id="u5-no" value="0" required>
                                    <label class="custom-control-label" for="u5-no">否</label>
                                </div>
                            </div>
                            <!-- 位置 -->
                            <div class="form-group mb-3 pt-2">
                                <label class="h6"><span class="text-primary">*06. </span>所在位置</label>
                                <div class="pr-5">
                                    <button type="button" class="btn btn-block text-left sign" onclick="address()">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                             fill="currentColor" class="bi bi-geo-alt-fill" viewBox="0 0 16 16">
                                            <path d="M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10zm0-7a3 3 0 1 1 0-6 3 3 0 0 1 0 6z"/>
                                        </svg>
                                        <span id="addressText"></span>
                                        <input id="addressInput" type="hidden" value="" name="add">
                                    </button>
                                </div>
                            </div>
                            <div class="form-group px-5">
                                <input type="hidden" name="sno" th:value="${session.user.no}">
                                <button id="sub-sign" type="submit" class="btn btn-primary btn-block" disabled>提交</button>
                            </div>
                        </form>
                    </div>
                    <input type="hidden" id="success-msg" th:value="${param.success}">
                    <input type="hidden" id="error-msg" th:value="${param.error}">
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"
        integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
        crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script th:src="@{/js/jquery.slim.min.js}"><\/script>')</script>
<script th:src="@{/js/bootstrap.bundle.min.js}"></script>
<script src="https://webapi.amap.com/maps?v=1.4.10&key=ccc557b111dd155750089e029fe3126e&plugin=AMap.AdvancedInfoWindow"></script>

<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
<script th:src="@{/js/user-info.js}"></script>
<script th:src="@{/js/dashboard.js}"></script>
<script th:src="@{/js/toastr.min.js}"></script>
<script th:src="@{/js/form-validation.js}"></script>
</body>
<script type="text/javascript" th:inline="javascript">
    function address() {
        var map = new AMap.Map("container", {resizeEnable: true});
        /**
         * 浏览器定位
         */
        //定位
        map.plugin('AMap.Geolocation', function () {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true, //是否使用高精度定位，默认:true
                timeout: 10000, //超过10秒后停止定位，默认：无穷大
                maximumAge: 0, //定位结果缓存0毫秒，默认：0
                convert: true, //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                showButton: true, //显示定位按钮，默认：true
                buttonPosition: 'LB', //定位按钮停靠位置，默认：'LB'，左下角
                buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                showMarker: true, //定位成功后在定位到的位置显示点标记，默认：true
                showCircle: true, //定位成功后用圆圈表示定位精度范围，默认：true
                panToLocation: true, //定位成功后将定位到的位置作为地图中心点，默认：true
                zoomToAccuracy: false, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                radius: 1000 //范围，默认：500
            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
            AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
        });
    }

    //解析定位结果
    function onComplete(data) {
        document.getElementById("addressText").innerText = data.formattedAddress
        $("#sub-sign").removeAttr("disabled")
        if (data.status == 1) {
            $("#addressInput").val(data.formattedAddress);
            sessionStorage.setItem("dingWei-lng", data.position.getLng());
            sessionStorage.setItem("dingWei-lat", data.position.getLat());
        }
    }
</script>
<script type="text/javascript" th:inline="javascript">
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function (e, xhr, options) {
        xhr.setRequestHeader(header, token);
    })

    function signE() {
        var stuno = $('#sno').val();
        $.ajax({
            url: "/security/find",
            type: "get",
            dataType: "json",
            data: {"sno": stuno},
            success: function (res) {
                if (res.status) {
                    let info = JSON.parse(res.value)
                    $("input[name='tw'][value='" + info.tw + "']").prop("checked","checked");
                    $("input[name='bd'][value='" + info.bd + "']").prop("checked","checked");
                    $("input[name='jc'][value='" + Number(info.jc) + "']").prop("checked","checked");
                    $("input[name='jc2'][value='" + Number(info.jcs) + "']").prop("checked","checked");
                    $("input[name='ss'][value='" + Number(info.cn) + "']").prop("checked","checked");
                    $("#addressText").text(info.address);
                    $("#MyMessage").show();
                }
            }
        })
    }

    function isEmpty(v) {
        switch (typeof v) {
            case 'undefined':
                return true;
            case 'string':
                if (v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
                break;
            case 'boolean':
                if (!v) return true;
                break;
            case 'number':
                if (0 === v || isNaN(v)) return true;
                break;
            case 'object':
                if (null === v || v.length === 0) return true;
                for (var i in v) {
                    return false;
                }
                return true;
        }
        return false;
    }

    function msg() {
        toastr.options.positionClass = 'toast-top-center';
        var errMsg = $('#error-msg').val();
        var succMsg = $('#success-msg').val();
        if (!isEmpty(succMsg)) {
            toastr.success('' + succMsg, '提示')
        } else if (!isEmpty(errMsg)) {
            toastr.error('' + errMsg, '错误')
        }
        return false
    }

    function app() {
        msg()
        findSign()
        signE()
    }
</script>
</html>
